<?php

/**
 * home actions.
 *
 * @package    dnevnik
 * @subpackage home
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class homeActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executePocetnaLand(sfWebRequest $request)
  {
     $this->setLayout('home');
  }

  public function executePocetna(sfWebRequest $request)
  {
     if($this->getUser()->hasCredential('roditelj'))
       $this->setLayout('roditelj');
  }

  public function executeWelcome(sfWebRequest $request)
  {
     $ucenik_one = DbFinder::from('Profil')->leftJoin('Profil.Id', 'Ucenik.Id')->where('Ucenik.RoditeljId', $this->getUser()->getAttribute('id'))->findFirst();

     $this->prezime = $ucenik_one->getPrezime();
     $this->setLayout('roditelj');
  }

  public function executeKorisniciprograma(sfWebRequest $request)
  {

  }

  public function executeNovosti(sfWebRequest $request)
  {

  }

  public function executeOpisprograma(sfWebRequest $request)
  {

  }

  public function executePressinformacije(sfWebRequest $request)
  {

  }

  public function executeKontakt(sfWebRequest $request)
  {
     if($this->getUser()->hasCredential('roditelj'))
       $this->setLayout('roditelj');
  }

  public function executeSkole(sfWebRequest $request)
  {
      $this->getContext()->getConfiguration()->loadHelpers(array('Tag', 'Url'));

      $this->gMap = new GMap(array('zoom'=>7, 'center_lat'=>44.5, 'center_lng'=>20.5));

      // adds a variable "markers" defined on the global level
      $this->gMap->addGlobalVariable('markers','new Array()');

      // creates a custom icon for markers
      /*$gMapIcon = new GMapIcon(
        'nice_icon',
        '/sfEasyGMapPlugin/images/nice_icon.png',
        array(
          'width'=>18,
          'height'=>25,
          'info_window_anchor_x'=>9,
          'info_window_anchor_y'=>25
        )
      );*/

      // creates two custom event listeners
      $gMapEvent1 = new GMapEvent(
        'mouseover',
        "document.getElementById('console_div').innerHTML = this.opis;"
      );
      $gMapEvent2 = new GMapEvent(
        'mouseout',
        "document.getElementById('console_div').innerHTML = '';"
      );

      $skolas = DbFinder::from('Skola')->join('SkolaOpis')->withColumn('SkolaOpis.Naslov', 'Naslov')->withColumn('SkolaOpis.Teaser', 'Teaser')->withColumn('SkolaOpis.XCor', 'X')->withColumn('SkolaOpis.YCor', 'Y')->find();
      foreach ($skolas as $key=>$skola)
      {
        // parameters: lat, lng, marker's javascript object's name, icon object
        $gMapMarker = new GMapMarker($skola->getColumn('X'), $skola->getColumn('Y'), 'markers['.$key.']');
        //$gMapMarker->addHtmlInfoWindow('<b>Adresa:</b><br />'.$skola->getAdresa());
        // will add a custom property to the marker's javascript object
        $naslov = $skola->getColumn('Naslov');
        if($naslov)
          $opis = '<h2>'.$naslov.','.'</h2>'.$skola->getColumn('Teaser');
        else $opis = ' ';
        $gMapMarker->setCustomProperty('opis', addslashes(str_replace("\r\n", " ", $opis)).link_to('Pročitaj više', 'home/detaljiSkole?skola_id='.$skola->getId(), array('target' => '_blank', 'onclick' => 'popup(this.href, "Detalji škole", 1024, 800); return false;')));
        // binds the event listeners to the marker
        $gMapMarker->addEvent($gMapEvent1);
        //$gMapMarker->addEvent($gMapEvent2);

        $this->gMap->addMarker($gMapMarker);
      }
  }

  public function executeDetaljiSkole(sfWebRequest $request)
  {
     $this->skola = DbFinder::from('Skola')->join('SkolaOpis')->withColumn('SkolaOpis.Naslov', 'Naslov')->withColumn('SkolaOpis.Content', 'Content')->where('Skola.Id', $request->getParameter('skola_id'))->findOne();

     $this->setLayout('skola');
  }

}